package com.ftf.tp.blog.application.dto.message.domain;

import com.ftf.tp.blog.domain.article.dos.SupportDO;
import com.ftf.tp.common.core.exception.BusinessException;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;

import java.util.Date;

/**
 * @author tanghao
 * @date 2022/8/25
 */
@Data
@Builder
@AllArgsConstructor
@NoArgsConstructor
public class ActionDO {

    private Long id;

    /**
     * 用户id
     */
    private Long userId;

    /**
     * 行为类型
     */
    private String action;

    /**
     * 目标类型
     */
    private String targetType;

    /**
     * 目标id
     */
    private String targetId;

    /**
     * 创建时间
     */
    private Date createdTime;

    public SupportDO toSupportDO() {
        int supportType;
        if ("support".equals(action)) {
            supportType = 0;
        } else if ("cancel_support".equals(action)) {
            supportType = 1;
        } else {
            throw new BusinessException("事件异常");
        }
        return SupportDO.builder()
                .supportTime(createdTime)
                .supportType(supportType)
                .targetType(targetType)
                .userId(userId)
                .build();
    }
}